package com.mago.tis.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.mago.tis.dao.ICompanyDao;
import com.mago.tis.dao.ITraderDao;
import com.mago.tis.daoImpl.CompanyDao;
import com.mago.tis.daoImpl.TraderDao;
import com.mago.tis.pojo.Tiscit;
import com.mago.tis.pojo.Tistit;
import com.mago.tis.service.ICompanyService;
import com.mago.tis.serviceImpl.BaseService;
import com.mago.tis.serviceImpl.TraderService;
import com.mago.tis.utility.ApplicationException;
import com.mago.tis.utility.ExceptionMessage;

public class CompanyService extends BaseService implements ICompanyService{
	
	private static final Logger logger = Logger.getLogger(TraderService.class);

	public boolean updateCompany(Tiscit tiscit) throws ApplicationException {
		ICompanyDao companyDao=new CompanyDao();
		boolean isUpdated=false;
		if(tiscit!=null){
			try{
				isUpdated=companyDao.updateCompanyInfo(tiscit);
			}
			catch (ApplicationException ae) {
				throw ae;
			} catch (Exception e) {
				logger.error("CompanyService : updateCompany() ----> "
						+ e.getMessage());
				throw new ApplicationException(
						ExceptionMessage.UPDATE_COMPANY_UNABLE);
			}
		
	}
		return isUpdated;
	}
	public List<Tiscit> getCompanyInfoById(String companyId)
			throws ApplicationException {
		ICompanyDao companyDao=new CompanyDao();
		List<Tiscit> companyInfo=new ArrayList<Tiscit>();
		try{
			companyInfo=companyDao.getCompanyOnId(companyId);
			logger.info("CompanyService : getCompanyInfoById() Traders List--> "+companyInfo.size());
		} 
		catch (ApplicationException ae) {
			logger.error("CompanyService : getCompanyInfoById() ----> "+ae);
			throw ae;
		}
		return companyInfo;
	}
	@Override
	public boolean updateAbout(Tiscit tiscit) throws ApplicationException {
		ICompanyDao companyDao=new CompanyDao();
		boolean isUpdated=false;
		if(tiscit!=null){
			try{
				isUpdated=companyDao.updateAboutInfo(tiscit);
			}
			catch (ApplicationException ae) {
				throw ae;
			} catch (Exception e) {
				logger.error("CompanyService : updateAbout() ----> "
						+ e.getMessage());
				throw new ApplicationException(
						ExceptionMessage.UPDATE_COMPANY_UNABLE);
			}
		
	}
		return isUpdated;
	
	}
}
